package com.prd.service.impl;

import com.prd.api.RemoteUserService;
import com.prd.service.UserService;
import com.prd.vo.UserBaseVo;
import com.prd.vo.UserVo;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class UserServiceImpl implements UserService {

    @Autowired
    private RemoteUserService remoteUserService;

    @Override
    public UserBaseVo listName(Long id) {
        List<UserBaseVo> listUserBaseVo = listName(new Long[]{id});
        UserBaseVo userBaseVo = new UserBaseVo();
        for (UserBaseVo userBaseVo1 : listUserBaseVo) {
            BeanUtils.copyProperties(userBaseVo1, userBaseVo);
        }
        return userBaseVo;
    }

    @Override
    public List<UserBaseVo> listName(Long[] ids) {
        List<UserVo> listUser = remoteUserService.listInfo(ids).getData();
        List<UserBaseVo> list = new ArrayList<>();
        for (UserVo userVo : listUser) {
            UserBaseVo userBaseVo = new UserBaseVo();
            userBaseVo.setId(userVo.getId());
            userBaseVo.setName(userVo.getName());
//            userBaseVo.setBranch();
//            userBaseVo.setPosition();
            userBaseVo.setMerge(userBaseVo.getName() + " " + userBaseVo.getBranch() + " " + userBaseVo.getPosition());
            userBaseVo.setPhone(String.valueOf(userVo.getTelephone()));
            userBaseVo.setHeadImg(userVo.getHeadImg());
            list.add(userBaseVo);
        }
        return list;
    }
}
